/**
 *
 *
 * @author TOTORO
 * @date 2021/7/20 15:19
 */
    var $nowSelect = jQuery;
    var $hidde = jQuery;
    var $clickBtn = jQuery;
    $(function() {
    $(".sq").click(function() {
        if ($(".dis").css("display") == "none") {
            $(".dis").show();
            $(".tx").text("收起");
            $(".put").css("border-width","0px 5px 8px")
        } else {
            $(".dis").hide();
            $(".tx").text("展开更多选项");
            $(".put").css("border-width","8px 5px 0px");
            $(".put").css("border-top-color","rgb(239, 239, 239)");
        }
    });
    //下拉框
    $(".trade-select").click(function() {
    $nowSelect = $(this);
    var id = $(this).attr("data-index");
    var c = $("#"+id).attr("data-x");
        var $x = $(this).offset().left;
        var $y = $(this).offset().top;
        // 调整位置
        $("#" + id).css({"top":parseInt($y)+30, "left":$x});
    if ($("#" + id).hasClass("rc-select-dropdown-hidden") == true) {
    $("#" + id).removeClass("rc-select-dropdown-hidden");
} else {
    $("#" + id).addClass("rc-select-dropdown-hidden").siblings(".rc-select-dropdown").addClass("rc-select-dropdown-hidden");
}
    $('div[data-x='+c+']')
    if ($(".trade-select").hasClass("rc-select-open") == true) {
    $(this).removeClass("rc-select-open")
} else {
    $(this).addClass("rc-select-open").siblings().removeClass("rc-select-open");
}
    $(document).mouseup(function(e) {
    var con = $('.trade-select');
    e.stopPropagation();
    if (con.has(e.target).length === 0) {
    $('.rc-select-dropdown').addClass("rc-select-dropdown-hidden");

}
});
    //小图标
    $(document).mouseup(function(e) {
    var con = $('.trade-select');
    e.stopPropagation();
    if (!con.is(e.target) && con.has(e.target).length === 0) {
    $(".trade-select").removeClass("rc-select-open");
}
});
});
    //下拉框点击赋值到文本框
    $(".rc-select-dropdown-menu li").hover(function() {
    $(this).addClass("selcc");
}, function() {
    $(this).removeClass("selcc");
});
    $(".rc-select-dropdown-menu li").click(function() {
    $(this).addClass("rc-select-dropdown-menu-item-selected").siblings().removeClass("rc-select-dropdown-menu-item-selected");
    var tx = $(this).text();
    $nowSelect.find(".textt").text(tx);
    $nowSelect.next().val($(this).attr("data-value"));
});

    //全选
    $('.all').on('click',function(){
    if(this.checked) {
    $(".sub").prop('checked',true);
}else {
    $(".sub").prop('checked',false);
}
});



        var Main = {
            methods: {
                open() {
                    var $td = $clickBtn.parents("td");
                    var orderId = $clickBtn.parents(".trade-order-main").attr("data-order-id");
                    this.$confirm('请确定派送员已经将包裹送出，该操作将不可撤回', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.$message({
                            type: 'success',
                            message: '改为发货状态成功'
                        });
                        $.ajaxSettings.async = false;
                        $.post("/order_logic/updateOrderStatus.htm", {"bizOrderId":orderId, "status":3}, function () {
                            $td.html($("<div>\n" +
                                "<p style='margin-bottom:3px;'>\n" +
                                "<span class='text-mod__link___1rXmw'>等待买家确认收货</span>\n" +
                                "</p>\n" +
                                "<div>\n" +
                                "<p style='margin-bottom:3px;'>\n" +
                                "<a href='' class='text-mod__link___1rXmw text-mod__secondary___2ghOD text-mod__hover___1TDrR' target='_blank' rel='noopener noreferrer'>详情</a>\n" +
                                "</p>\n" +
                                "</div>\n" +
                                "</div>"));
                        });
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消'
                        });
                    });
                }
            }
        }
        var Ctor = Vue.extend(Main)
        new Ctor().$mount('#app3')
});

    //ttr news
$(function () {
    $(".ship").click(function () {
        $clickBtn = $(this);
        $("#ship-button").click();
    })
    // 点击关闭交易，获取指定订单号与iframe传输
    $(".cancel-pay").click(function () {
        // 获取订单号
        var bizOrderId = $(this).parents(".trade-order-main").attr("data-order-id");
        var $cancelPayIframe = $("<div class='tm-dialog ' tabindex='0' role='dialog' style='width: 400px; height: 300px; left: 752px; top: 604px;' data-reactid='.6.$dialog'>\n" +
            "    <div class='tm-dialog-content' data-reactid='.6.$dialog.0'><a tabindex='0' class='tm-dialog-close' data-reactid='.6.$dialog.0.0'>\n" +
            "        <span class='tm-dialog-close-x iconfont icon-close' style='font-size: 23px;'></span>\n" +
            "    </a>\n" +
            "        <div class='tm-dialog-body' data-reactid='.6.$dialog.0.2'>\n" +
            "            <iframe class='iframe-mod__iframe___31VVd iframe-mod__embed___Kqj5i' src='/seller/cancel_order.htm?bizOrderId="+bizOrderId+"&from=listSoldItems'></iframe>\n" +
            "            <style>\n" +
            "                .iframe-mod__embed___Kqj5i {\n" +
            "                    width: 100%;\n" +
            "                    height: 100%;\n" +
            "                }\n" +
            "                .iframe-mod__iframe___31VVd {\n" +
            "                    border: none;\n" +
            "                }\n" +
            "\n" +
            "            </style>\n" +
            "        </div>\n" +
            "    </div>\n" +
            "    <div tabindex='0' style='width:0;height:0;overflow:hidden;' data-reactid='.6.$dialog.1'>sentinel</div>\n" +
            "</div>").appendTo("body");
        $(".tm-dialog-mask").show();
    });
    // 关闭交易里的关闭
    $("body").on("click", ".tm-dialog-close-x", function () {
        $(".tm-dialog").remove();
        $(".tm-dialog-mask").hide();
    });




    // 多条件操作
    // 点击表格上方的指定位置，给上对应参数
    $(".tabs-mod__tab___1e6Y8").click(function () {
        var postion = $(this).attr("data-position");
        var newUrl = Totoro.changeURLPar(window.location.href, "tabCode", postion);
        window.location.href = Totoro.changeURLPar(newUrl, "ttr", document.documentElement.scrollTop || document.body.scrollTop);;
    });

    // 搜索订单
    $("#searchOrder").click(function () {
        // 获取所有的参数
        var auctionId = $("#auctionId").val();
        var itemName = $("#itemName").val();
        var buyerNick = $("#buyerNick").val();
        var bizOrderId = $("#bizOrderId").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        var evaStatus = $("#evaStatus").val();
        var saleAfter = $("#saleAfter").val();
        const urlObject = {
            "auctionId": auctionId
            ,"itemName": itemName
            ,"buyerNick": buyerNick
            ,"bizOrderId": bizOrderId
            ,"startTime": startTime
            ,"endTime": endTime
            ,"evaStatus": evaStatus
            ,"saleAfter": saleAfter
        }
        // 清除URL所有参数
        var newUrl = window.location.href.toString().split("?")[0];
        // 制作新参数
        for (let key in urlObject){
            var val = urlObject[key];
            if(val != ''){
                newUrl = Totoro.changeURLPar(newUrl, key, val);
            }
        }
        window.location.href = Totoro.changeURLPar(newUrl, "ttr", document.documentElement.scrollTop || document.body.scrollTop);;
    });

    // 重置
    $("#reset").click(function () {
        var newUrl = window.location.href.toString().split("?")[0];
        window.location.href = Totoro.changeURLPar(newUrl, "ttr", document.documentElement.scrollTop || document.body.scrollTop);;
    });

    // 不显示关闭的订单
    $("#hideCloseOrder").click(function () {
        var isHide = new Boolean($(this).prop("checked"));
        var newUrl = Totoro.changeURLPar(window.location.href, "notShowCloseOrder", isHide);
        window.location.href = Totoro.changeURLPar(newUrl, "ttr", document.documentElement.scrollTop || document.body.scrollTop);
    });

    // 修改全选，普通选中状态
    // 普选判断，如果所有可以选中的都选了，则自动勾选全选
    $(".item-checkbox").click(function () {
       var $notCheckedLength = $(".item-checkbox:not(:disabled)").length;
       var $checkedLength = $(".item-checkbox:not(:disabled):checked").length;
       var checked = $checkedLength == $notCheckedLength;
           $(".sub-all").each(function () {
               $(this).prop("checked", checked);
           })
    });

    // 全选判断
    $(".sub-all").click(function () {
        var checked = $(this).prop("checked");
        $(".sub-all").each(function () {
            $(this).prop("checked", checked);
        });
        $(".item-checkbox:not(:disabled)").each(function () {
            $(this).prop("checked", checked);
        });
    })

    // 批量发货
    $(".superShip").click(function () {
        // 判断用户是否选择了商品
        var isChecked = $(".item-checkbox:not(:disabled):checked").length > 0;
        if(isChecked){
            layer.confirm('是否批量发货?', {
                btn: ['确定','取消'], //按钮
                title: '已卖出的宝贝',
                offset: '300px'
            }, function(){
                var orderIds = new Array();
                $(".item-checkbox:not(:disabled):checked").each(function () {
                    orderIds.push($(this).parents(".trade-order-main").attr("data-order-id"));
                });
                $.post("/order_logic/batchUpdateOrderStatus.htm", {"bizOrderIds": orderIds, "status": 3}, function (res) {
                    layer.msg('确认发货成功，本次发货了'+$(".item-checkbox:not(:disabled):checked").length+'个宝贝！', {offset: '300px'});
                    setTimeout(v =>{
                        window.location.reload();
                    }, 400);
                })
            }, function(){
                layer.msg('已取消', {offset: '300px'});
            });
        } else{
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.alert('<p style="color: #f40">请先选择发货的宝贝</p>', {title: '已卖出的宝贝', offset: '300px'});
            });
        }
    });

    // 修改详情订单价格
    $('.updatePrice').click(function () {
        var _this = $(this);
        var nowPrice = $(this).parent().attr("data-price");
        layui.use('layer', function() {
            var layer = layui.layer;
            layer.prompt({
                formType: 0,
                value: parseFloat(nowPrice+".0"),
                title: '修改该宝贝实际价格',
                offset: '300px'
            }, function (value, index, elem) {
                var isNumber = Totoro.finalIsNumber(value);
                if(!isNumber){
                    layer.msg('请输入数字！', {offset: '300px'});
                    return false;
                }
                if(parseFloat(value) < 1){
                    layer.msg('价格必须大于1！', {offset: '300px'});
                    return false;
                }
                // 获取修改的该次详情订单号码
                var srId = _this.parents(".sr-box").attr("data-sr-id");
                $.post("/order_logic/updateSrOrderPayPrice.htm", {"srId": srId, "payPrice": parseFloat(value)}, function (res) {
                    layer.msg('修改成功！', {offset: '300px'});
                    _this.parent().attr("data-price", value);
                    _this.parent().parent().parent().prev().prev().find("strong").children(":eq(1)").text(value+".00");
                    layer.close(index);
                })
            });
        });
    });

    // 上方分页按钮控制分页
    $("#prevCurr").click(function () {
        var curr = parseInt(Totoro.getQueryVariable("curr"))-1;
        var newUrl = Totoro.changeURLPar(window.location.href, "curr", curr);
        window.location.href = newUrl;
    });
    $("#nextCurr").click(function () {
        var curr = parseInt(Totoro.getQueryVariable("curr"))+1;
        var newUrl = Totoro.changeURLPar(window.location.href, "curr", curr);
        window.location.href = newUrl;
    })

    // 下方的分页开始了
    layui.use(['laypage', 'layer'], function() {
        var laypage = layui.laypage
            , layer = layui.layer;
        //完整功能
        laypage.render({
            elem: 'tmallPagination'
            , count: $("#allPage").val()
            , theme: '#2485D7'
            , limit: 10
            , layout: ['count', 'prev', 'page', 'next', 'skip']
            , curr: Totoro.getQueryVariable("curr")
            , jump: function(obj, first){
                //首次不执行
                if(!first){
                    var curr = Totoro.getQueryVariable("curr");
                    var newUrl = Totoro.changeURLPar(window.location.href, "curr", obj.curr);
                    window.location.href = newUrl;
                }
            }
        });
    });



})

$(document).ready(function () {
    document.documentElement.scrollTop = $("#scroll").val();
})


